package com.ruoyi.user.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.ruoyi.common.core.cg.pojo.Group;
import com.ruoyi.common.core.cg.pojo.JoinGroupInfo;
import com.ruoyi.common.core.cg.dto.JoinGroupParams;
import com.ruoyi.common.core.cg.result.PageResult;
import com.ruoyi.common.core.cg.dto.QueryPageBean;
import com.ruoyi.common.core.cg.result.Result;
import com.ruoyi.user.service.GroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("group")
public class GroupController {
    @Autowired
    private GroupService service;

    /**
     * 分页查询
     * @param queryPageBean 查询参数
     * @return
     */
    @RequestMapping("findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        try {
            return service.findPage(queryPageBean);
        }catch (Exception e){
            return new PageResult(0L,null);
        }
    }

    /**
     * 拼团ID
     * @param id
     * @return
     */
    @RequestMapping("findById")
    public Result findById(Integer id){
        try {
            return service.findById(id);
        }catch (Exception e){
            return new Result(false,"查询失败");
        }
    }

    /**
     * 查询加入拼团后的信息
     * @param id
     * @return
     */
    @RequestMapping("findJoinGroupInfo")
    public Result findJoinGroupInfo(Integer id){
        try {
            JoinGroupInfo joinGroupInfo = service.findJoinGroupInfo(id);
            return new Result(true,"查询成功",joinGroupInfo);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"查询失败");
        }
    }
    @RequestMapping("joinGroup")
    public Result joinGroup(@RequestBody JoinGroupParams joinGroupParams){
        try {
            return service.joinGroup(joinGroupParams);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"拼团失败");
        }
    }

}
